﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>部门管理</title>
    <#--freemrak引入模板文件 是使用相对路径来引入的-->
    <#include "../common/link.ftl"/>
    <script>
        $(function () {
            //添加新增/编辑的点击事件
            $('.btn-input').click(function () {
                //获取事件源绑定的数据,使用data方法可以很方便的获取data-*开头的属性数据
                var json = $(this).data('json');
                if(json){//如果有值就是修改
                    $('input[name="id"]').val(json.id);
                    $('input[name="name"]').val(json.name);
                    $('input[name="sn"]').val(json.sn);
                }
                //弹出模态框
                $("#myModel").modal("show");

            })
            //添加保存按钮点击
            $('.btn-submit').click(function () {

                //使用jquery-form插件来提交表单 (有表单的情况使用该插件,写的代码比较少)
                $("#editForm").ajaxSubmit(function (data) {//前提是from表单写了action和method
                    if(data.success){
                        $.messager.popup("保存成功");
                        window.setTimeout(function () {
                            window.location.reload();
                        },1000);
                    }else{
                        $.messager.alert("温馨提示",data.msg);
                    }
                })
                /*//提交异步请求
                $.post('/department/saveOrUpdate.do',$("#editForm").serialize(),function (data) {
                    if(data.success){
                        $.messager.popup("保存成功");
                        window.setTimeout(function () {
                            window.location.reload();
                        },1000);
                    }else{
                        $.messager.alert("温馨提示",data.msg);
                    }
                })*/
            })
            //删除按钮
            $(".btn-delete").click(function () {
                var id = $(this).data("id");
                $.messager.confirm("警告","是否确认删除信息",function () {
                    $.post('/department/delete.do',{id:id},handlerMessage)
                });
            })
        })
    </script>
</head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">
    <!--引入页面头部-->
    <#include "../common/navbar.ftl"/>
    <!--菜单回显  声明变量=设置值-->
    <#assign currentMenu="department"/>
    <%--引入菜单--%>
    <#include "../common/menu.ftl"/>
    <div class="content-wrapper">
        <section class="content-header">
            <h1>部门管理</h1>
        </section>
        <section class="content">
            <div class="box">
                <!--高级查询--->
                <form class="form-inline" id="searchForm" action="/department/list.do" method="post">
                    <input type="hidden" name="currentPage" id="currentPage" value="1">
                    <a href="#" class="btn btn-success btn-input" style="margin: 10px">
                        <span class="glyphicon glyphicon-plus"></span> 添加
                    </a>
                </form>
                <!--编写内容-->
                <div class="box-body table-responsive no-padding ">
                    <table class="table table-hover table-bordered">
                        <tr>
                            <th>编号</th>
                            <th>部门名称</th>
                            <th>部门编号</th>
                            <th>操作</th>
                        </tr>
                            <#list result.list as department>
                                <tr>
                                    <#--freemark取值如果是空值会报异常-->
                                        <#--在值后面加一个!不会报异常-->
                                        <#--在!后加字符串可以将空值设置为默认值-->
                                        <#--index从0开始计数可以增加起始索引-->
                                    <td>${department_index+1}</td>
                                    <td>${department.name!}</td>
                                    <td>${department.sn!}</td>
                                    <#--${department.sn!"无"} 如果值是null,显示为无-->
                                    <td>
                                        <a href="" class="btn btn-info btn-xs btn-input" data-json='${department.json}'  data-toggle ='modal'>
                                            <#--使用data-*绑定自定义数据-->
                                            <span class="glyphicon glyphicon-pencil" ></span> 编辑
                                        </a>
                                        <a href="#" data-id='${department.id}' class="btn btn-danger btn-xs btn-delete">
                                            <span class="glyphicon glyphicon-trash"></span> 删除
                                        </a>
                                    </td>
                                </tr>
                            </#list>
                    </table>

                    <!--分页-->
                    <#include "../common/page.ftl"/>

                </div>
            </div>
        </section>
    </div>
    <!--底部页面-->
    <#include "../common/footer.ftl"/>
</div>
<#--模态框-->
<div class="modal fade" tabindex="-1" role="dialog" id="myModel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">新增/编辑</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/department/saveOrUpdate.do" method="post" id="editForm">
                    <input type="hidden" name="id">
                    <div class="form-group" style="margin-top: 10px;">
                        <label for="name" class="col-sm-3 control-label">名称：</label>
                        <div class="col-sm-7">
                            <input type="text" class="form-control" id="name" name="name"
                                   placeholder="请输入部门名">
                        </div>
                    </div>
                    <div class="form-group" style="margin-top: 10px;">
                        <label for="sn" class="col-sm-3 control-label">编码：</label>
                        <div class="col-sm-7">
                            <input type="text" class="form-control" id="sn" name="sn"
                                   placeholder="请输入部门编码">
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary btn-submit">保存</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->
</body>
</html>
